home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / MNuntius.cp < prev    next >
Encoding:
Text File  |  1994-03-12  |  2.5 KB  |  130 lines  |  [TEXT/MPS ]

  1. // Copyright © 1992 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // MNuntius.cp
  3.  
  4. #include "UNewsAppl.h"
  5. #include "UMacTcp.h"
  6. #include "UNntp.h"
  7. #include "FileTools.h"
  8. #include "FastBits.h"
  9. #include "MyDontDeadStrip.h"
  10. #include "Tools.h"
  11. #include "UFatalError.h"
  12.  
  13. #include <RsrcGlobals.h>
  14. #include <ErrorGlobals.h>
  15. #include <Memory.h>
  16. #include <UGridView.h>
  17. #include <UDialog.h>
  18. #include <UTEView.h>
  19. #include <UPrinting.h>
  20. #include <Resources.h>
  21. #include <Packages.h>
  22. #include <UFloatWindow.h>
  23.  
  24. #pragma segment Main
  25.  
  26. void MakeAllSegmentsResident()
  27. {
  28. #if 0
  29.     gUnloadAllSegs = false;
  30.     short maxNo = CountResources('CODE');
  31.     for (short i = 1; i <= maxNo; i++)
  32.     {
  33.         Handle h = GetIndResource('CODE', i);
  34.         FailNILResource(h);
  35.         CStr255 name;
  36.         short resID;
  37.         ResType theType;
  38.         GetResInfo(h, resID, theType, name);
  39.         if (resID > 0)
  40.         {
  41.             HLockHi(h);
  42.             SetResidentSegment(resID, true);
  43.         }
  44.     }
  45. #endif
  46. }
  47.  
  48. void CreateStdErr()
  49. {
  50. #if qDebug & 0
  51.     CStr255 s, num;
  52.     unsigned long uli;
  53.     GetDateTime(uli);
  54.     NumToString(long(uli) & 0xFFFFF, num);
  55.     s = "HD2:Desktop Folder:Nuntius_";
  56.     s += num;
  57.     FILE *file = fopen(s, "w");
  58.     if (file)
  59.     {
  60.         fclose(file);
  61.         fsetfileinfo(s, 'MPS ', 'TEXT');
  62.         file = fopen(s, "w");
  63.         _iob[2] = *file;  // _iob[2] = stderr
  64.         Ptr p = NewPtr(300);
  65. //        setvbuf(file, p, _IOLBF, 256); // flush at newline
  66.     }
  67. #endif
  68. }
  69.  
  70. void OpenConnectionToTheWorld()
  71. {
  72.     if (GetResource('CMNU', mTest) == nil)
  73.     {
  74.         InitUMacTCP(); // no doubt when q_Final
  75.     }
  76.     else
  77.     {
  78.         KeyMap theKeys;
  79.         GetKeys(theKeys);
  80.         Boolean useNntp = (theKeys[1] & 1) == 0;
  81.         if (gConfiguration.machineType == 26) // 26 == Q950
  82.             useNntp = !useNntp;
  83.         if (!useNntp)
  84.             DoUseFakeNntp();
  85.         else
  86.             InitUMacTCP();
  87.     }
  88. #if qDebug
  89.     fprintf(stderr, "Uses %s nntp\n", UsesFakeNntp() ? "fake" : "real");
  90. #endif
  91.     FlushVols();
  92. }
  93.  
  94. void main()
  95. {
  96.     if (qDebug && IsControlKeyDown())
  97.         DebugStr("At real start...");
  98.      InitToolBox();
  99.     if (gConfiguration.systemVersion < 0x0700)
  100.     {
  101.         // ugly to check for version
  102.         SetCursor(qd.arrow);
  103.         Alert(phNeedSystem7, nil);
  104.         ExitToShell();
  105.     }
  106.     ShowSplashScreen();
  107.     InitUMacApp(50);
  108.     InitUFatalError();
  109.     InitUPtrObject();
  110.     InitUTools();
  111.     CreateStdErr();
  112.     FlushVols();
  113.     MakeAllSegmentsResident();
  114.     InitUGridView();
  115.     InitUTEView();
  116.     InitUDialog();
  117.     InitUPrinting();
  118. //@    InitUFloatWindow();
  119.     InitUFastBits();
  120.     MyDontDeadStrip();
  121.     if (qDebug && IsControlKeyDown())
  122.         DebugStr("Jumping off...");
  123.     OpenConnectionToTheWorld();
  124.  
  125.     gNewsAppl = new TNewsAppl;
  126.     gNewsAppl->INewsAppl();
  127.     gNewsAppl->Run();
  128.     gNewsAppl = nil; // CleanupMacApp frees gApplication
  129. }
  130.